package com.store.orm.mongo.datasource;

import com.mongodb.MongoClient;
import com.mongodb.client.MongoDatabase;
import com.store.orm.config.MongoConfig;

import java.util.Map;

/**
 * 获取一个连接
 *
 * @author 宫静雨
 * @version 1.0
 */
public class UnPooledConnection {

    public MongoDatabase get(MongoConfig config) {
        MongoClient client = new MongoClient(config.getHost(), config.getPort());
        return client.getDatabase(config.getDb());
    }

    public MongoDatabase get(Map<String, MongoConfig> map, String key) {
        MongoConfig config = map.get(key);
        return new MongoClient(config.getHost(), config.getPort()).getDatabase(config.getDb());
    }
}